package org.jcut.controller;

import java.util.UUID;

import org.jcut.bean.Type;
import org.jcut.data.Data;
import org.jcut.service.TyepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/type")
public class TypeController {
	@Autowired
	private TyepService service;
	@Autowired
	private Data data;
	@RequestMapping("/selectAll")
	public Object selectAll() {
		data.setMyData(1, "查询成功", service.selectAll());
		return data;
	}
	@RequestMapping("/add")
	public Object add(Type type) {
		type.setId(UUID.randomUUID().toString());
		int i=service.insert(type);
		data.setMyData(i, i>0?"添加完成":"添加失败", i);
		return data;
	}
	@RequestMapping("/updateDis")
	public Object updateDis(Type type) {
		int i=service.updateDis(type);
		data.setMyData(i, i>0?"修改成功":"服务器异常", i);
		return data;
	}
	@RequestMapping("/adminSelectAll")
	public Object adminSelectAll(@RequestParam(value="pageNum",required = false)String pageNum,@RequestParam(value="pageSize",required = false) String pageSize) {
		if ((pageNum != null && !("".equals(pageNum))) && (pageSize != null && !("".equals(pageSize)))) {
			PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
		}
		
		data.setMyData(1, "查询成功", new PageInfo<>(service.adminSelectAll()));
		
		return data;
	}
}
